import SceneKit

class Animations {
    static func create(withName name: String, endTime: TimeInterval) -> SCNAnimationPlayer? {
        guard let animation = SCNScene(named: "\(name).scn")?.rootNode.animationKeys.first else { return nil }
        
        // Set end time for the animation.
        if var animSource = animation.animation().source as? CAKeyframeAnimation {
            animSource.duration = endTime
            
            let player = SCNAnimationPlayer(source: animSource)
            return player
        }
        return nil
    }
}